import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.ListCellRenderer;
import javax.swing.ListSelectionModel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.text.BadLocationException;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

public class DBTestFrame extends JFrame {
	private static final long serialVersionUID = 1L;

	private JPanel contentPane;

	private MovieTableModel movieTableModel;
	private JTable tableResult;
	private JTextField textFieldMovieID;
	private JTextField textFieldUserID;
	private JList<Object> listUserMovieTypes, listMFMovieTypes;
	private JTextField textFieldMFTitle;
	private JTextField textFieldMFDirector;
	private JTextField textFieldMFStartDate;
	private JTextField textFieldMFEndDate;
	private JTextField textFieldMFIndex;
	private JTextField textFieldMFLength;
	private JComboBox<Object> queryComboBox;
	private JTextPane textPaneMFActors, textPaneResult;
	private Style redStyle, blackStyle, greenStyle;
	private JScrollPane scrollPane;
	private JButton btnExecute;
	private CheckListItem[] checkListItemUser, checkListItemMF;

	/**
	 * Create the frame.
	 */
	@SuppressWarnings("unchecked")
	public DBTestFrame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 777, 723);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.NORTH);
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[] { 0, 0 };
		gbl_panel.rowHeights = new int[] { 0, 0, 0, 0, 0 };
		gbl_panel.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
		gbl_panel.rowWeights = new double[] { 1.0, 1.0, 1.0, 1.0,
				Double.MIN_VALUE };
		panel.setLayout(gbl_panel);

		JPanel panel_2 = new JPanel();
		panel_2.setBorder(new TitledBorder(null, "Query", TitledBorder.LEADING,
				TitledBorder.TOP, null, null));
		GridBagConstraints gbc_panel_2 = new GridBagConstraints();
		gbc_panel_2.insets = new Insets(0, 0, 5, 0);
		gbc_panel_2.fill = GridBagConstraints.BOTH;
		gbc_panel_2.gridx = 0;
		gbc_panel_2.gridy = 0;
		panel.add(panel_2, gbc_panel_2);
		GridBagLayout gbl_panel_2 = new GridBagLayout();
		gbl_panel_2.columnWidths = new int[] { 0, 0, 0, 0 };
		gbl_panel_2.rowHeights = new int[] { 0, 0 };
		gbl_panel_2.columnWeights = new double[] { 0.0, 1.0, 0.0,
				Double.MIN_VALUE };
		gbl_panel_2.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
		panel_2.setLayout(gbl_panel_2);

		JLabel lblQuery = new JLabel("Query:");
		GridBagConstraints gbc_lblQuery = new GridBagConstraints();
		gbc_lblQuery.insets = new Insets(0, 0, 0, 5);
		gbc_lblQuery.anchor = GridBagConstraints.EAST;
		gbc_lblQuery.gridx = 0;
		gbc_lblQuery.gridy = 0;
		panel_2.add(lblQuery, gbc_lblQuery);

		queryComboBox = new JComboBox<Object>();
		GridBagConstraints gbc_queryComboBox = new GridBagConstraints();
		gbc_queryComboBox.insets = new Insets(0, 0, 0, 5);
		gbc_queryComboBox.fill = GridBagConstraints.HORIZONTAL;
		gbc_queryComboBox.gridx = 1;
		gbc_queryComboBox.gridy = 0;
		panel_2.add(queryComboBox, gbc_queryComboBox);

		btnExecute = new JButton("Execute");
		getRootPane().setDefaultButton(btnExecute);
		GridBagConstraints gbc_btnExecute = new GridBagConstraints();
		gbc_btnExecute.gridx = 2;
		gbc_btnExecute.gridy = 0;
		panel_2.add(btnExecute, gbc_btnExecute);

		JPanel panel_3 = new JPanel();
		panel_3.setBorder(new TitledBorder(null, "Movie", TitledBorder.LEADING,
				TitledBorder.TOP, null, null));
		GridBagConstraints gbc_panel_3 = new GridBagConstraints();
		gbc_panel_3.insets = new Insets(0, 0, 5, 0);
		gbc_panel_3.fill = GridBagConstraints.BOTH;
		gbc_panel_3.gridx = 0;
		gbc_panel_3.gridy = 1;
		panel.add(panel_3, gbc_panel_3);
		GridBagLayout gbl_panel_3 = new GridBagLayout();
		gbl_panel_3.columnWidths = new int[] { 0, 0, 0 };
		gbl_panel_3.rowHeights = new int[] { 0, 0 };
		gbl_panel_3.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
		gbl_panel_3.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
		panel_3.setLayout(gbl_panel_3);

		JLabel lblId = new JLabel("ID:");
		GridBagConstraints gbc_lblId = new GridBagConstraints();
		gbc_lblId.insets = new Insets(0, 0, 0, 5);
		gbc_lblId.anchor = GridBagConstraints.EAST;
		gbc_lblId.gridx = 0;
		gbc_lblId.gridy = 0;
		panel_3.add(lblId, gbc_lblId);

		textFieldMovieID = new JTextField();
		GridBagConstraints gbc_textFieldMovieID = new GridBagConstraints();
		gbc_textFieldMovieID.fill = GridBagConstraints.HORIZONTAL;
		gbc_textFieldMovieID.gridx = 1;
		gbc_textFieldMovieID.gridy = 0;
		panel_3.add(textFieldMovieID, gbc_textFieldMovieID);
		textFieldMovieID.setColumns(10);

		JPanel panel_4 = new JPanel();
		panel_4.setBorder(new TitledBorder(null, "User", TitledBorder.LEADING,
				TitledBorder.TOP, null, null));
		GridBagConstraints gbc_panel_4 = new GridBagConstraints();
		gbc_panel_4.insets = new Insets(0, 0, 5, 0);
		gbc_panel_4.fill = GridBagConstraints.BOTH;
		gbc_panel_4.gridx = 0;
		gbc_panel_4.gridy = 2;
		panel.add(panel_4, gbc_panel_4);
		GridBagLayout gbl_panel_4 = new GridBagLayout();
		gbl_panel_4.columnWidths = new int[] { 0, 0, 0 };
		gbl_panel_4.rowHeights = new int[] { 0, 0, 0, 0 };
		gbl_panel_4.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
		gbl_panel_4.rowWeights = new double[] { 0.0, 0.0, 1.0, Double.MIN_VALUE };
		panel_4.setLayout(gbl_panel_4);

		JLabel lblId_1 = new JLabel("ID:");
		GridBagConstraints gbc_lblId_1 = new GridBagConstraints();
		gbc_lblId_1.insets = new Insets(0, 0, 5, 5);
		gbc_lblId_1.anchor = GridBagConstraints.EAST;
		gbc_lblId_1.gridx = 0;
		gbc_lblId_1.gridy = 0;
		panel_4.add(lblId_1, gbc_lblId_1);

		textFieldUserID = new JTextField();
		GridBagConstraints gbc_textFieldUserID = new GridBagConstraints();
		gbc_textFieldUserID.insets = new Insets(0, 0, 5, 0);
		gbc_textFieldUserID.fill = GridBagConstraints.HORIZONTAL;
		gbc_textFieldUserID.gridx = 1;
		gbc_textFieldUserID.gridy = 0;
		panel_4.add(textFieldUserID, gbc_textFieldUserID);
		textFieldUserID.setColumns(10);

		JLabel lblMovieTypes = new JLabel("Movie types:");
		GridBagConstraints gbc_lblMovieTypes = new GridBagConstraints();
		gbc_lblMovieTypes.anchor = GridBagConstraints.NORTH;
		gbc_lblMovieTypes.insets = new Insets(0, 0, 5, 5);
		gbc_lblMovieTypes.gridx = 0;
		gbc_lblMovieTypes.gridy = 1;
		panel_4.add(lblMovieTypes, gbc_lblMovieTypes);

		JScrollPane scrollPane_2 = new JScrollPane();
		scrollPane_2.setPreferredSize(new Dimension(4, 50));
		GridBagConstraints gbc_scrollPane_2 = new GridBagConstraints();
		gbc_scrollPane_2.insets = new Insets(0, 0, 5, 0);
		gbc_scrollPane_2.fill = GridBagConstraints.BOTH;
		gbc_scrollPane_2.gridx = 1;
		gbc_scrollPane_2.gridy = 1;
		panel_4.add(scrollPane_2, gbc_scrollPane_2);

		listUserMovieTypes = new JList<Object>(new CheckListItem[] {});
		scrollPane_2.setViewportView(listUserMovieTypes);
		listUserMovieTypes.setCellRenderer(new CheckListRenderer());
		listUserMovieTypes
				.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		listUserMovieTypes.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent event) {
				try {
					@SuppressWarnings("rawtypes")
					JList<Object> list = (JList) event.getSource();

					// Get index of item clicked

					int index = list.locationToIndex(event.getPoint());
					CheckListItem item = (CheckListItem) list.getModel()
							.getElementAt(index);

					// Toggle selected state

					item.setSelected(!item.isSelected());

					// Repaint cell

					list.repaint(list.getCellBounds(index, index));
				} catch (Exception e) {
				}
			}
		});

		JPanel panel_5 = new JPanel();
		panel_5.setBorder(new TitledBorder(null, "Movie Filter",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		GridBagConstraints gbc_panel_5 = new GridBagConstraints();
		gbc_panel_5.fill = GridBagConstraints.BOTH;
		gbc_panel_5.gridx = 0;
		gbc_panel_5.gridy = 3;
		panel.add(panel_5, gbc_panel_5);
		GridBagLayout gbl_panel_5 = new GridBagLayout();
		gbl_panel_5.columnWidths = new int[] { 0, 0, 0 };
		gbl_panel_5.rowHeights = new int[] { 0, 0 };
		gbl_panel_5.columnWeights = new double[] { 1.0, 1.0, Double.MIN_VALUE };
		gbl_panel_5.rowWeights = new double[] { 1.0, Double.MIN_VALUE };
		panel_5.setLayout(gbl_panel_5);

		JPanel panel_6 = new JPanel();
		GridBagConstraints gbc_panel_6 = new GridBagConstraints();
		gbc_panel_6.insets = new Insets(0, 0, 0, 5);
		gbc_panel_6.fill = GridBagConstraints.BOTH;
		gbc_panel_6.gridx = 0;
		gbc_panel_6.gridy = 0;
		panel_5.add(panel_6, gbc_panel_6);
		GridBagLayout gbl_panel_6 = new GridBagLayout();
		gbl_panel_6.columnWidths = new int[] { 0, 0, 0 };
		gbl_panel_6.rowHeights = new int[] { 0, 0, 0, 0, 0 };
		gbl_panel_6.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
		gbl_panel_6.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0,
				Double.MIN_VALUE };
		panel_6.setLayout(gbl_panel_6);

		JLabel lblTitle = new JLabel("Title:");
		GridBagConstraints gbc_lblTitle = new GridBagConstraints();
		gbc_lblTitle.insets = new Insets(0, 0, 5, 5);
		gbc_lblTitle.anchor = GridBagConstraints.EAST;
		gbc_lblTitle.gridx = 0;
		gbc_lblTitle.gridy = 0;
		panel_6.add(lblTitle, gbc_lblTitle);

		textFieldMFTitle = new JTextField();
		GridBagConstraints gbc_textFieldMFTitle = new GridBagConstraints();
		gbc_textFieldMFTitle.insets = new Insets(0, 0, 5, 0);
		gbc_textFieldMFTitle.fill = GridBagConstraints.HORIZONTAL;
		gbc_textFieldMFTitle.gridx = 1;
		gbc_textFieldMFTitle.gridy = 0;
		panel_6.add(textFieldMFTitle, gbc_textFieldMFTitle);
		textFieldMFTitle.setColumns(10);

		JLabel lblStartdate = new JLabel("StartDate:");
		GridBagConstraints gbc_lblStartdate = new GridBagConstraints();
		gbc_lblStartdate.anchor = GridBagConstraints.EAST;
		gbc_lblStartdate.insets = new Insets(0, 0, 5, 5);
		gbc_lblStartdate.gridx = 0;
		gbc_lblStartdate.gridy = 1;
		panel_6.add(lblStartdate, gbc_lblStartdate);

		textFieldMFStartDate = new JTextField();
		GridBagConstraints gbc_textFieldMFStartDate = new GridBagConstraints();
		gbc_textFieldMFStartDate.insets = new Insets(0, 0, 5, 0);
		gbc_textFieldMFStartDate.fill = GridBagConstraints.HORIZONTAL;
		gbc_textFieldMFStartDate.gridx = 1;
		gbc_textFieldMFStartDate.gridy = 1;
		panel_6.add(textFieldMFStartDate, gbc_textFieldMFStartDate);
		textFieldMFStartDate.setColumns(10);

		JLabel lblIndex = new JLabel("Index:");
		GridBagConstraints gbc_lblIndex = new GridBagConstraints();
		gbc_lblIndex.anchor = GridBagConstraints.EAST;
		gbc_lblIndex.insets = new Insets(0, 0, 5, 5);
		gbc_lblIndex.gridx = 0;
		gbc_lblIndex.gridy = 2;
		panel_6.add(lblIndex, gbc_lblIndex);

		textFieldMFIndex = new JTextField();
		GridBagConstraints gbc_textFieldMFIndex = new GridBagConstraints();
		gbc_textFieldMFIndex.insets = new Insets(0, 0, 5, 0);
		gbc_textFieldMFIndex.fill = GridBagConstraints.HORIZONTAL;
		gbc_textFieldMFIndex.gridx = 1;
		gbc_textFieldMFIndex.gridy = 2;
		panel_6.add(textFieldMFIndex, gbc_textFieldMFIndex);
		textFieldMFIndex.setColumns(10);

		JLabel lblActors = new JLabel("Actors:");
		GridBagConstraints gbc_lblActors = new GridBagConstraints();
		gbc_lblActors.anchor = GridBagConstraints.NORTHEAST;
		gbc_lblActors.insets = new Insets(0, 0, 0, 5);
		gbc_lblActors.gridx = 0;
		gbc_lblActors.gridy = 3;
		panel_6.add(lblActors, gbc_lblActors);

		JScrollPane scrollPane_3 = new JScrollPane();
		GridBagConstraints gbc_scrollPane_3 = new GridBagConstraints();
		gbc_scrollPane_3.fill = GridBagConstraints.BOTH;
		gbc_scrollPane_3.gridx = 1;
		gbc_scrollPane_3.gridy = 3;
		panel_6.add(scrollPane_3, gbc_scrollPane_3);

		textPaneMFActors = new JTextPane();
		scrollPane_3.setViewportView(textPaneMFActors);

		JPanel panel_7 = new JPanel();
		GridBagConstraints gbc_panel_7 = new GridBagConstraints();
		gbc_panel_7.fill = GridBagConstraints.BOTH;
		gbc_panel_7.gridx = 1;
		gbc_panel_7.gridy = 0;
		panel_5.add(panel_7, gbc_panel_7);
		GridBagLayout gbl_panel_7 = new GridBagLayout();
		gbl_panel_7.columnWidths = new int[] { 0, 0, 0 };
		gbl_panel_7.rowHeights = new int[] { 0, 0, 0, 0, 0 };
		gbl_panel_7.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
		gbl_panel_7.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0,
				Double.MIN_VALUE };
		panel_7.setLayout(gbl_panel_7);

		JLabel lblDirector = new JLabel("Director:");
		GridBagConstraints gbc_lblDirector = new GridBagConstraints();
		gbc_lblDirector.insets = new Insets(0, 0, 5, 5);
		gbc_lblDirector.anchor = GridBagConstraints.EAST;
		gbc_lblDirector.gridx = 0;
		gbc_lblDirector.gridy = 0;
		panel_7.add(lblDirector, gbc_lblDirector);

		textFieldMFDirector = new JTextField();
		GridBagConstraints gbc_textFieldMFDirector = new GridBagConstraints();
		gbc_textFieldMFDirector.insets = new Insets(0, 0, 5, 0);
		gbc_textFieldMFDirector.fill = GridBagConstraints.HORIZONTAL;
		gbc_textFieldMFDirector.gridx = 1;
		gbc_textFieldMFDirector.gridy = 0;
		panel_7.add(textFieldMFDirector, gbc_textFieldMFDirector);
		textFieldMFDirector.setColumns(10);

		JLabel lblEndDate = new JLabel("End Date:");
		GridBagConstraints gbc_lblEndDate = new GridBagConstraints();
		gbc_lblEndDate.anchor = GridBagConstraints.EAST;
		gbc_lblEndDate.insets = new Insets(0, 0, 5, 5);
		gbc_lblEndDate.gridx = 0;
		gbc_lblEndDate.gridy = 1;
		panel_7.add(lblEndDate, gbc_lblEndDate);

		textFieldMFEndDate = new JTextField();
		GridBagConstraints gbc_textFieldMFEndDate = new GridBagConstraints();
		gbc_textFieldMFEndDate.insets = new Insets(0, 0, 5, 0);
		gbc_textFieldMFEndDate.fill = GridBagConstraints.HORIZONTAL;
		gbc_textFieldMFEndDate.gridx = 1;
		gbc_textFieldMFEndDate.gridy = 1;
		panel_7.add(textFieldMFEndDate, gbc_textFieldMFEndDate);
		textFieldMFEndDate.setColumns(10);

		JLabel lblLength = new JLabel("Length:");
		GridBagConstraints gbc_lblLength = new GridBagConstraints();
		gbc_lblLength.anchor = GridBagConstraints.EAST;
		gbc_lblLength.insets = new Insets(0, 0, 5, 5);
		gbc_lblLength.gridx = 0;
		gbc_lblLength.gridy = 2;
		panel_7.add(lblLength, gbc_lblLength);

		textFieldMFLength = new JTextField();
		GridBagConstraints gbc_textFieldMFLength = new GridBagConstraints();
		gbc_textFieldMFLength.insets = new Insets(0, 0, 5, 0);
		gbc_textFieldMFLength.fill = GridBagConstraints.HORIZONTAL;
		gbc_textFieldMFLength.gridx = 1;
		gbc_textFieldMFLength.gridy = 2;
		panel_7.add(textFieldMFLength, gbc_textFieldMFLength);
		textFieldMFLength.setColumns(10);

		JLabel lblTypes = new JLabel("Types:");
		GridBagConstraints gbc_lblTypes = new GridBagConstraints();
		gbc_lblTypes.anchor = GridBagConstraints.NORTH;
		gbc_lblTypes.insets = new Insets(0, 0, 0, 5);
		gbc_lblTypes.gridx = 0;
		gbc_lblTypes.gridy = 3;
		panel_7.add(lblTypes, gbc_lblTypes);

		JScrollPane scrollPane_4 = new JScrollPane();
		scrollPane_4.setPreferredSize(new Dimension(4, 50));
		GridBagConstraints gbc_scrollPane_4 = new GridBagConstraints();
		gbc_scrollPane_4.fill = GridBagConstraints.BOTH;
		gbc_scrollPane_4.gridx = 1;
		gbc_scrollPane_4.gridy = 3;
		panel_7.add(scrollPane_4, gbc_scrollPane_4);

		listMFMovieTypes = new JList<Object>();
		scrollPane_4.setViewportView(listMFMovieTypes);
		listMFMovieTypes.setCellRenderer(new CheckListRenderer());
		listMFMovieTypes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		listMFMovieTypes.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent event) {
				try {
					@SuppressWarnings("rawtypes")
					JList<Object> list = (JList) event.getSource();

					// Get index of item clicked

					int index = list.locationToIndex(event.getPoint());
					CheckListItem item = (CheckListItem) list.getModel()
							.getElementAt(index);

					// Toggle selected state

					item.setSelected(!item.isSelected());

					// Repaint cell

					list.repaint(list.getCellBounds(index, index));
				} catch (Exception e) {
				}
			}
		});

		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new TitledBorder(null, "Result",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		contentPane.add(panel_1, BorderLayout.CENTER);
		GridBagLayout gbl_panel_1 = new GridBagLayout();
		gbl_panel_1.columnWidths = new int[] { 605 };
		gbl_panel_1.rowHeights = new int[] { 100, 0 };
		gbl_panel_1.columnWeights = new double[] { 1.0 };
		gbl_panel_1.rowWeights = new double[] { 0.0, 1.0 };
		panel_1.setLayout(gbl_panel_1);

		scrollPane = new JScrollPane();
		scrollPane.setPreferredSize(new Dimension(4, 100));
		GridBagConstraints gbc_scrollPane = new GridBagConstraints();
		gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
		gbc_scrollPane.fill = GridBagConstraints.BOTH;
		gbc_scrollPane.gridx = 0;
		gbc_scrollPane.gridy = 0;
		panel_1.add(scrollPane, gbc_scrollPane);

		textPaneResult = new JTextPane();
		scrollPane.setViewportView(textPaneResult);
		redStyle = textPaneResult.addStyle("Red style", null);
		StyleConstants.setForeground(redStyle, Color.RED);
		blackStyle = textPaneResult.addStyle("Black style", null);
		StyleConstants.setForeground(blackStyle, Color.BLACK);
		greenStyle = textPaneResult.addStyle("Green style", null);
		StyleConstants.setForeground(greenStyle, Color.GREEN);

		JScrollPane scrollPane_1 = new JScrollPane();
		GridBagConstraints gbc_scrollPane_1 = new GridBagConstraints();
		gbc_scrollPane_1.fill = GridBagConstraints.BOTH;
		gbc_scrollPane_1.gridx = 0;
		gbc_scrollPane_1.gridy = 1;
		panel_1.add(scrollPane_1, gbc_scrollPane_1);

		tableResult = new JTable();
		tableResult.setFillsViewportHeight(true);
		scrollPane_1.setViewportView(tableResult);
		movieTableModel = new MovieTableModel(new ArrayList<Movie>());
		tableResult.setModel(movieTableModel);
		tableResult.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
	}

	// Represents items in the list that can be selected

	class CheckListItem {
		private String label;
		private boolean isSelected = false;

		public CheckListItem(String label) {
			this.label = label;
		}

		public boolean isSelected() {
			return isSelected;
		}

		public void setSelected(boolean isSelected) {
			this.isSelected = isSelected;
		}

		public String toString() {
			return label;
		}
	}

	// Handles rendering cells in the list using a check box

	@SuppressWarnings({ "serial", "rawtypes" })
	class CheckListRenderer extends JCheckBox implements ListCellRenderer {
		public Component getListCellRendererComponent(JList list, Object value,
				int index, boolean isSelected, boolean hasFocus) {
			setEnabled(list.isEnabled());
			setSelected(((CheckListItem) value).isSelected());
			setFont(list.getFont());
			setBackground(list.getBackground());
			setForeground(list.getForeground());
			setText(value.toString());
			return this;
		}
	}

	public void showMovies(List<Movie> movies) {
		movieTableModel.setMovies(movies);
		textPaneResult.setText("Movies found: " + movies.size());
	}

	public void setMovieTypesList(List<MovieType> types) {
		checkListItemUser = new CheckListItem[types.size()];
		checkListItemMF = new CheckListItem[types.size()];
		for (int i = 0; i < types.size(); i++) {
			checkListItemUser[i] = new CheckListItem(types.get(i).getKey());
			checkListItemMF[i] = new CheckListItem(types.get(i).getKey());
		}
		listUserMovieTypes.setListData(checkListItemUser);
		listMFMovieTypes.setListData(checkListItemMF);
	}

	public void setQueries(List<QueryEnum> queries) {
		DefaultComboBoxModel<Object> model = new DefaultComboBoxModel<Object>(
				queries.toArray());
		queryComboBox.setModel(model);
	}

	public QueryEnum getSelectedQuery() {
		return (QueryEnum) queryComboBox.getSelectedItem();
	}

	public void setErrorOnParameters() {
		StyledDocument doc = textPaneResult.getStyledDocument();
		textPaneResult.setText("");
		try {
			doc.insertString(doc.getLength(),
					"Errori nei parametri inseriti!\n", redStyle);
			scrollPane.getVerticalScrollBar().setValue(
					scrollPane.getVerticalScrollBar().getMaximum());
		} catch (BadLocationException e) {
		}
	}

	public void addQueryExecutorListener(ActionListener listener) {
		btnExecute.addActionListener(listener);
	}

	public String getMovieID() {
		return textFieldMovieID.getText();
	}

	public void showDetailedMovie(DetailedMovie detMovie) {
		textPaneResult.setText(detMovie.toString());

	}

	public void setMessage(String message) {
		textPaneResult.setText(message);
	}

	public void showMovieTypes(List<MovieType> types) {
		textPaneResult.setText("Movie types:\n" + types);

	}

	public String getUserID() {
		return textFieldUserID.getText();
	}

	public void showUser(User user) {
		textPaneResult.setText(user.toString());

	}

	public MovieFilter getMovieFilter() {
		try {
			String title = textFieldMFTitle.getText();
			String director = textFieldMFDirector.getText();

			DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
			df.setLenient(false);

			Date startSQLDate = null;
			if (!textFieldMFStartDate.getText().equals("")) {
				java.util.Date startDate = df.parse(textFieldMFStartDate
						.getText());
				startSQLDate = new Date(startDate.getTime());
			}

			Date endSQLDate = null;
			if (!textFieldMFEndDate.getText().equals("")) {
				java.util.Date endDate = df.parse(textFieldMFEndDate.getText());
				endSQLDate = new Date(endDate.getTime());
			}

			int startIndex = 0;
			if (!textFieldMFIndex.getText().equals(""))
				startIndex = Integer.parseInt(textFieldMFIndex.getText());

			int length = 0;
			if (!textFieldMFLength.getText().equals(""))
				length = Integer.parseInt(textFieldMFLength.getText());

			String actors = textPaneMFActors.getText();
			List<String> actorsList = new ArrayList<String>();
			if (!actors.equals("")) {
				String[] a = actors.split("\\r?\\n");
				for (String s : a) {
					actorsList.add(s);
				}
			}

			List<MovieType> types = new ArrayList<MovieType>();
			if (checkListItemMF != null) {
				for (CheckListItem item : checkListItemMF) {
					if (item.isSelected())
						types.add(new MovieType(item.toString()));
				}
			}

			MovieFilter filter = new MovieFilter(title, actorsList, director,
					startSQLDate, endSQLDate, startIndex, length, types);

			return filter;
		} catch (Exception e) {
			return null;
		}
	}

	public int getStartIndex() {
		int startIndex = 0;
		if (!textFieldMFIndex.getText().equals("")) {
			try {
				startIndex = Integer.parseInt(textFieldMFIndex.getText());
			} catch (Exception e) {
				startIndex = -1;
			}
		}
		
		return startIndex;
	}

	public int getLength() {
		int length = 0;
		if (!textFieldMFLength.getText().equals("")) {
			try {
				length = Integer.parseInt(textFieldMFLength.getText());
			} catch (Exception e) {
				length = -1;
			}
		}
		return length;
	}

	public void showMessage(String string) {
		textPaneResult.setText(string);
		
	}

	public User getUser() {
		if(!getUserID().equals("")){
			List<MovieType> types = new ArrayList<MovieType>();
			if (checkListItemUser != null) {
				for (CheckListItem item : checkListItemUser) {
					if (item.isSelected())
						types.add(new MovieType(item.toString()));
				}
			}
			return new User(getUserID(), types);
		}else
			return null;
	}

}
